package com.sl.au.service.impl;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.sl.au.entity.PaymentLog;
import com.sl.au.repository.OperateLogRepository;
import com.sl.au.repository.PaymentLogRepository;
import com.sl.au.repository.PaymentPlanRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.sl.au.service.PayPlanService;

import java.util.Date;

@Service("payPlanService")
@Transactional
public class PayPlanServiceImpl extends BaseServiceImpl implements PayPlanService {
	@PersistenceContext
	private EntityManager em;
	@Autowired
	PaymentLogRepository paymentLogRepository;
	@Override
	public void payNotionalPooling(String contractId,String payMan) {
		try {
			if (StringUtils.hasText(contractId)) {
				this.em.createNativeQuery("{call getContractBillInfo(?)}")
						.setParameter(1, contractId)
						.executeUpdate();
			}
		}
		catch(Exception e)
		{
			// TODO Auto-generated method stub
			PaymentLog paymentLog=new PaymentLog();
			paymentLog.setContractID(contractId);
			paymentLog.setOperateDate(new Date());
			paymentLog.setOperateMan(payMan);
			paymentLog.setContent(e.getMessage());
			paymentLogRepository.save(paymentLog);
		}
	}

}
